import request from '@/utils/request'

// // 增加方志
// export const userRegisterService = ({ username, password, repassword }) =>
//   request.post('/reg', { username, password, repassword })

// 分类名字数组
const categoryPath = ['', '/territory', '/constellation', '/school-palace', '/city', '/offices',
  '/irrigation', '/temple', '/scenic-spots', '/others']


// 上传图片
export const uploadImgService = data => {
  return request({
    method: 'POST',
    url: '/upload',
    data,
    headers: { // 设置请求头
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}


export const saveRecordService = data => {
  return request.post('/records', data)
}
export const saveCategoryService = (data, categoryId) => {
  return request.post(`${categoryPath[categoryId]}`, data, {
    headers: {
      'Content-Type': 'application/json',
    }
  })
}
// 获取某个方志的某个分类下的所有舆图
export const getCategoryList = (categoryId, recordid) => {
  return request.get(`${categoryPath[categoryId]}/${recordid}`)
}


// catalogList


export const searchService = (name) => {
  console.log(name)
  return request.get('/records/search', { params: { name } })
}

export const getCityList = (province) => {
  return request.get('/records/city', {
    params: {
      province
    }
  })
}
export const getCountyList = (city) => {
  return request.get('/records/county', {
    params: {
      city
    }
  })
}



export const getRecord = (field, level) => {
  return request.get(`/records`, { params: { field, level } })
}


export const getRecordField = (field) => {
  return request.get(`/records`, field)
}


export const getRecordByIdService = (id) => {
  return request.get(`/records/${id}`)
}
// /offices/{id}

export const getMapService = (id) => {
  return request.get(`/offices/${id}`)
}
// imgList

export const getBgcImg = (id) => {
  return request.get(`/offices/${id}`)
}

